package com.java0108;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Test02 {
}
class Server02{
    public static void main(String[] args) throws IOException {
        //创建服务器套接字
        ServerSocket serverSocket = new ServerSocket(8081);
        //创建套接字:接收请求
        while (true) {
            Socket socket = serverSocket.accept();
            //从套接字里获取输入流
            InputStream inputStream = socket.getInputStream();
            byte[] arr = new byte[1024];
            int len = inputStream.read(arr);
            System.out.println(new String(arr, 0, len));
        }

    }

}
//客户端
class Client02{
    public static void main(String[] args) throws IOException {
        //创建套接字对象，需要指定ip和port
        //ipconfig:查地址
        Socket socket = new Socket("192.168.1.150",8081);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello".getBytes());
    }

}